/**
 * 订单管理
 * @author 康文程
 * @date 2024-1-10
 */
class Orders {
    /**
     * 根据订单号查询订单
     * @param orderId 订单号
     * @return {Promise<string>}
     */
    getOrderByOrderId(orderId){
        return new Promise((resolve, reject) => {
            $.ajax({
                url: "/www.xiaomi.com/background/orders",
                method: "GET",
                data: {
                    orderId:orderId
                },
                success: function (response) {
                    resolve(response);
                },
                error: function (error) {
                    reject(error);
                }
            });
        });
    }
    /**
     * 根据物流公司Id查询物流站和送货人
     * @param logisticsCompaniesId 订单号
     * @return {Promise<json>}
     */
    getLogisticsStationsByLogisticsCompanyId(logisticsCompaniesId){
        return new Promise((resolve, reject) => {
            $.ajax({
                url: "/www.xiaomi.com/background/logistics/stations",
                method: "GET",
                data: {
                    logisticsCompaniesId:logisticsCompaniesId
                },
                success: function (response) {
                    resolve(response);
                },
                error: function (error) {
                    reject(error);
                }
            });
        });
    }
    /**
     * 根据货源编号查询推荐选择
     * @param warehouseId 货源编号
     * @return {Promise<json>}
     */
    getWarehouseById(warehouseId){
        return new Promise((resolve, reject) => {
            $.ajax({
                url: "/www.xiaomi.com/background/recommend/select/warehouse",
                method: "GET",
                data: {
                    warehouseId:warehouseId
                },
                success: function (response) {
                    resolve(response);
                },
                error: function (error) {
                    reject(error);
                }
            });
        });
    }
    /**
     * 根据货源编号查询推荐选择
     * @param warehouseId 货源编号
     * @return {Promise<json>}
     */
    getAllWarehousesExcept(warehouseId){
        return new Promise((resolve, reject) => {
            $.ajax({
                url: "/www.xiaomi.com/background/select/warehouse",
                method: "GET",
                data: {
                    warehouseId:warehouseId
                },
                success: function (response) {
                    resolve(response);
                },
                error: function (error) {
                    reject(error);
                }
            });
        });
    }
    /**
     * 根据订单编号修改货源编号
     * @param orderId 订单编号
     * @param warehouseId 货源编号
     * @return {Promise<boolean>}
     */
    updateWarehouseIdByOrderId(orderId,warehouseId){
        return new Promise((resolve, reject) => {
            $.ajax({
                url: "/www.xiaomi.com/background/change/source",
                method: "POST",
                data: {
                    orderId:orderId,
                    warehouseId:warehouseId
                },
                success: function (response) {
                    resolve(response);
                },
                error: function (error) {
                    reject(error);
                }
            });
        });
    }
    /**
     * 订单管理分页条件筛选
     * @param sort 排序
     * @param currentPage 当前页码
     * @param totalPages 总页数
     * @param state 订单状态
     * @param nameOrId 收货人名字或订单Id
     * @param menuId 菜单Id
     * @return {Promise<string>} html页面
     */
    orderManagement(sort,currentPage,totalPages,state,nameOrId,menuId){
        return new Promise((resolve, reject) => {
            $.ajax({
                url: "/www.xiaomi.com/background/home",
                method: "GET",
                data: {
                    menuId:menuId,
                    sort:sort,
                    currentPage:currentPage,
                    totalPages:totalPages,
                    state : state,
                    nameOrId : nameOrId
                },
                success: function (response) {
                    resolve(response);
                },
                error: function (error) {
                    reject(error);
                }
            });
        });
    }
    /**
     * 订单发货
     * @param commodityId 商品ID
     * @param quantity 商品件数
     * @param shippingMethod 运货方式
     * @param logisticsCompanies 物流公司
     * @param logisticsStation 物流站
     * @param trackingNumber 订单号
     * @return {Promise<boolean>}
     */
    ordersShipments(commodityId,quantity,shippingMethod,logisticsCompanies,logisticsStation,trackingNumber){
        return new Promise((resolve, reject) => {
            $.ajax({
                url: "/www.xiaomi.com/orders/shipments",
                method: "GET",
                data: {
                    commodityId : commodityId,
                    quantity : quantity,
                    shippingMethod : shippingMethod,
                    logisticsCompanies : logisticsCompanies,
                    logisticsStation : logisticsStation,
                    trackingNumber : trackingNumber
                },
                success: function (response) {
                    resolve(response);
                },
                error: function (error) {
                    reject(error);
                }
            });
        });
    }
    /**
     * 修改指定物流公司
     * @param logisticsCompaniesJson 物流公司JSON
     * @return {Promise<json>}
     */
    updateLogisticsCompaniesById(logisticsCompaniesJson){
        return new Promise((resolve, reject) => {
            $.ajax({
                url: "/www.xiaomi.com/background/modify/logistics/companies",
                method: "POST",
                data:{
                    logisticsCompaniesJson:logisticsCompaniesJson
                },
                success: function (response) {
                    resolve(response);
                },
                error: function (error) {
                    reject(error);
                }
            });
        });
    }
    /**
     * 删除指定物流站
     * @param stationId 物流站Id
     * @return {Promise<boolean>}
     */
    removeStation(stationId){
        return new Promise((resolve, reject) => {
            $.ajax({
                url: "/www.xiaomi.com/background/remove/station",
                method: "GET",
                data:{
                    stationId:stationId
                },
                success: function (response) {
                    resolve(response);
                },
                error: function (error) {
                    reject(error);
                }
            });
        });
    }
    /**
     * 新增物流公司
     * @param logisticsCompaniesJson 物流公司Json
     * @return {Promise<boolean>}
     */
    addLogisticsCompanies(logisticsCompaniesJson){
        return new Promise((resolve, reject) => {
            $.ajax({
                url: "/www.xiaomi.com/background/new/logistics/companies",
                method: "POST",
                data:{
                    logisticsCompaniesJson:JSON.stringify(logisticsCompaniesJson)
                },
                success: function (response) {
                    resolve(response);
                },
                error: function (error) {
                    reject(error);
                }
            });
        });
    }
    /**
     * 新增物流站
     * @param logisticsStationJson 物流站Json
     * @return {Promise<boolean>}
     */
    addLogisticsStation(logisticsStationJson){
        return new Promise((resolve, reject) => {
            $.ajax({
                url: "/www.xiaomi.com/background/new/logistics/station",
                method: "POST",
                data:{
                    logisticsStationJson:JSON.stringify(logisticsStationJson)
                },
                success: function (response) {
                    resolve(response);
                },
                error: function (error) {
                    reject(error);
                }
            });
        });
    }
    /**
     * 修改订单状态
     * @param status 订单状态
     * @param orderId 订单Id
     * @return {Promise<boolean>}
     */
    updateOrderStatusByOrderId(orderId,status){
        return new Promise((resolve, reject) => {
            $.ajax({
                url: "/www.xiaomi.com/background/modify/orders/status",
                method: "POST",
                data:{
                    orderId:orderId,
                    status:status
                },
                success: function (response) {
                    resolve(response);
                },
                error: function (error) {
                    reject(error);
                }
            });
        });
    }

}